package com.example.xinlijiankangsys.service;

import com.example.xinlijiankangsys.mapper.UserMapper;
import com.example.xinlijiankangsys.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    private static final Logger log = LoggerFactory.getLogger(UserService.class);
    @Autowired
    private UserMapper userMapper;
    public User isUserExist(String userId, String password) {
        return userMapper.selectUserByUserIdAndPassword(userId,password);
    }
    public boolean insertUser(User user) {
        boolean res=false;
        try{
            if(userMapper.insertUser(user)==1)res=true;
        }catch (Exception e){
            log.error("用户注册失败");
        }
        return res;
    }

    /**
     * 检查用户ID是否存在
     * @param userId 用户ID
     * @return 存在返回true，否则false
     */
    public boolean isUserExist(String userId) {
        return userMapper.countUserByUserId(userId) > 0;
    }

}